import { createRouter, createWebHashHistory } from 'vue-router'
// 导入组件
import Layout from '@/views/Layout'
import Home from '@/views/Home'

// 一级目录
import Category from '@/views/Category/index.vue'
// 二级
import SubCategory from '@/views/Category/sub.vue'
// 商品详情
import Goods from '@/views/Goods'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      {
        path: '/category/:id',
        component: Category
      },
      {
        path: '/category/sub/:id',
        component: SubCategory
      },
      {
        path: '/goods/:id',
        component: Goods
      }
    ]
  }
]

// vue2是new一个router实例
const router = createRouter({
  history: createWebHashHistory(), // hash模式 | createWebHistory history模式
  routes
})

export default router
